#include "MapZone.h"
#include <GL/glew.h>
#include "../log.h"
#include "../common.h"
#include "../drawing.h"

#include <LightImage.h>
#include <map>
#include <string>

namespace Tmpl {

// MapZoneTexture
typedef std::map<std::string, unsigned int> TextureMap;
static TextureMap sTextures;
MapZoneTexture::MapZoneTexture(const char* filename)
{
	// Set Default variables
	mName = filename;
	mTexId = -1;
	mDensity = 0.5f;
	mSlopeMin = 0.0f;
	mSlopeMax = 1.0f;
	mHeightMin = 0.0f;
	mHeightMax = 1.0f;
	mSlopeFalloff = 0.1f;
	mHeightFalloff = 0.1f;
}

// Map Zone Type
MapZoneType::MapZoneType(float roughness, float mountains, float mountainFrequency)
{
	mRoughness = roughness;
	mMountains = mountains;
	mMountainFrequency = mountainFrequency;
}

// Map Zone
MapZone::MapZone(MapZoneType* type, Vec2f pos)
{
	mType = type;
	mPos = pos;
}

void MapZone::AddLink(MapZone* zone)
{
	if (isLinked(zone)) return;

	// Create a new link
	MapZoneLink* link = new MapZoneLink();
	link->zone = zone;
	link->distance = (mPos - zone->GetPos()).Length();
	mLinks.push_back(link);
}

void MapZone::RemoveLink(MapZone* zone)
{
	std::deque<MapZoneLink*>::iterator it;
	for (it = mLinks.begin(); it!= mLinks.end(); ++it)
	{
		if ((*it)->zone == zone)
		{
			delete *it;
			mLinks.erase(it);
			break;
		}
	}
}

MapZoneLink* MapZone::GetLink(MapZone* zone) const
{
	std::deque<MapZoneLink*>::const_iterator it;
	for (it = mLinks.begin(); it!= mLinks.end(); ++it)
	{
		if ((*it)->zone == zone)
		{
			return *it;
		}
	}
	return 0;
}


}